﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <script language="javascript">
        function myClass() {
            //此处相当于构造函数
        }
        var obj1 = new myClass();
        //添加属性
        obj1.ID = 1;
        obj1.Name = "johnson";

        //添加方法
        obj1.showMessage = function (t1) {
            alert("ID: " + this.ID + ", Name: " + this.Name + t1);
        }

        alert(obj1.Name);
        obj1.showMessage("xxx");

        var obj1 = {};
        var obj2 =
         {
             ID: 2,
             Name: "Johnson222",
             showMessage: function () {
                 alert("ID: " + this.ID + "Name: " + this.Name);
             }
         }
        obj2.showMessage();

        function myClass() {
        }

        myClass.prototype.ID = 1;
        myClass.prototype.Name = "johnson";
        myClass.prototype.showMessage = function () {
            alert("ID: " + this.ID + "Name: " + this.Name);
        }

        var obj1 = new myClass();
        obj1.showMessage();

        function myClass() {
            //添加属性
            this.ID = 1;
            this.Name = "johnson";

            //添加方法
            this.showMessage = function () {
                alert("ID: " + this.ID + ", Name: " + this.Name);
            }
        }

        var obj1 = new myClass();
        var obj2 = new myClass();
    </script>
</body>
</html>
